// pages/pets/pets.js
import { Pets } from '../pets/pets-model.js';
var pets = new Pets();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex: 1,
    selected: true,
    selected1: false,
    isLoadedAll: false,
    loadingHidden: false,
    petsArr: [],
  },

  selected: function (e) {
    this.setData({
      selected1: false,
      selected: true
    })
  },
  selected1: function (e) {
    this.setData({
      selected: false,
      selected1: true
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._loadData();
  },

  // 加载数据
  _loadData: function (callback) {
    var that = this;

    pets.getMyPets((res) => {
      console.log(res)
      that.setData({
        petsData: res,
        loadingHidden: true
      });
    })

    pets.getCollect(this.data.pageIndex, (res) => {
      that.setData({
        collectData: res.data
      });
    })

  },

  // 创建宠物
  onCreatePets: function (e) {
    wx.navigateTo({
      url: '../create-pets/create-pets',
    })
  },


  onPetsInfo: function (e) {
    var id = pets.getDataSet(e, 'id');
    wx.navigateTo({
      url: '../pets-info/pets-info?id=' + id,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this._loadData();
  },
})